﻿package  {
	import lib.*;
	import crypt.*;
	import flash.utils.*;
	import flash.display.*;
	import Module.LoadingScreen.LoadingScreen;
	import Module.LoginScreen.LoginScreen;
	import Module.HomeScreen.HomeScreen;
	import Module.GameScreen.GameScreen;
	import Module.GameScreen.MenuComponent;

	public class Main extends MovieClip implements Parameters{
		private var conn:Connection;
		public var user:userInfo;
		public var gameInfo:GameInfo;
		public var loadingScreen:LoadingScreen;
		public var loginScreen:LoginScreen;
		public var homeScreen:HomeScreen;
		public var gameScreen:GameScreen;
		public function Main() {
			// constructor code
			user = new userInfo();
			gameInfo = new GameInfo();
			conn = new Connection();
			conn.connect("123.30.50.73",6667);
			this.listener();
			this.onLoadingScreen();
			
		}
		
		private function listener():void{
			this.conn.registerReceivedPassivePacket(LGI_1,"LGI-1",this);
		}
		public function setConnection(conn:Connection):void{
			this.conn = conn;
		}
		
		public function getConnection():Connection{
			return conn;
		}
		public function onLoadingScreen():void{
			loadingScreen = new LoadingScreen(this);
			this.addChild(loadingScreen);
		}
		
		public function onLoginScreen():void{
			if(loadingScreen)
			{
				this.removeChild(loadingScreen);
				loadingScreen = null;
			}
			if(gameScreen)
			{
				this.removeChild(gameScreen);
				gameScreen = null;
			}
			loginScreen = new LoginScreen(this);
			this.addChild(loginScreen);
		}
		
		public function onHomeScreen():void{
			if(loginScreen)
			{
				this.removeChild(loginScreen);
				loginScreen = null;
			}
			homeScreen = new HomeScreen(this);
			this.addChild(homeScreen);
		}
		
		public function onGameScreen():void{
			if(loginScreen)
			{
				this.removeChild(loginScreen);
				loginScreen = null;
			}
			
			gameScreen = new GameScreen(this);
			this.addChild(gameScreen);
		}
		private function LGI_1(recvPacket:Packet , args:Parameters):void{
			recvPacket.print();
			this.onLoginScreen();
		}

	}
	
}
